package com.chery.media.ui.play

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.chery.media.R
import com.chery.media.library.extend.toColorInt
import com.chery.media.network.model.MusicTypeBean

class MusicPlayTypeAdapter: BaseQuickAdapter<MusicTypeBean, BaseViewHolder>(R.layout.item_music_type) {

    private var selectIndex = 0

    override fun convert(holder: BaseViewHolder, item: MusicTypeBean) {
        holder.apply {
            setImageResource(R.id.typeIcon, if (selectIndex != layoutPosition) item.unSelectResId?:0 else item.selectedResId?:0)
            setText(R.id.typeName, item.name)
            setTextColor(R.id.typeName, if (selectIndex != layoutPosition) R.color.public_66FFFFFF.toColorInt() else R.color.public_FDCD19.toColorInt())
            setBackgroundResource(R.id.selectArea, if (selectIndex == layoutPosition) R.drawable.shape_set_selected_bg else R.color.transparent)
            setGone(R.id.selectLine, selectIndex != layoutPosition)
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setSelect(index: Int) {
        this.selectIndex = index
        notifyDataSetChanged()
    }

}